<?php
namespace Project_725;
use TwinPeaks\Core\Http as Http;

require __DIR__ . '/../AppProject_725.php';

class Test_API extends \PHPUnit_Framework_TestCase
{
	/**
	 * 
	 */
	function __construct()
	{
		parent::__construct();
		Http\CUri::setDefaultHost('geomania.local');
		$_SERVER['REQUEST_METHOD'] = 'POST';
	}

	function testPing()
	{
		$app = AppProject_725::handleRequest("/api/lm/ping") // No trailing slash. Will test ::alterRequestURI method
			->setOption(AppProject_725::OPT_RETURN_FRONT_CONTROLLER_OUTPUT)
		;
		$json = $app->run();
		$response = json_decode($json);
		$this->assertEquals($response->header->status, 1);
	}

	function testSaveLoc()
	{
		$_POST['lat'] = '22.23';
		$_POST['long'] = '22.3';
		
		$app = AppProject_725::handleRequest("/api/lm/save_loc/")
			->setOption(AppProject_725::OPT_RETURN_CONTROLLER_OUTPUT)
		;		
		
		$_POST['access_token'] = $app->getConfig()->API_AccessToken;		
		$result = $app->run();
		$this->assertTrue($result);
	}
	
	function testFilter()
	{
		$app = AppProject_725::handleRequest("/api/lm/signup/")
			->setOption(AppProject_725::OPT_RETURN_FRONT_CONTROLLER_OUTPUT)
		;		
		$app->run();
		
		$_POST['type'] = 1;
		$_POST['email'] = 'a.samuylik@gmail.com';
		$_POST['access_token'] = 'a.samuylik_debug';
		$filter = $app->getCurrentRule()->getController()->getFilter();
		
		$this->assertEquals($filter->getType(), 1);
		$this->assertEquals($filter->getEmail(), 'a.samuylik@gmail.com');
	}
}
